<?php

abstract class Base_View
{
	protected $data = array();
	protected $title;
	
	public function __construct( $data = array() )
	{
		$this->setData( $data);
		$this->pageHeader();
	}
	
	abstract public function doView();
	
	public function setData( $newData )
	{
		$this->data = $newData;
	}
	
	protected function pageHeader()
	{
		$b_info = get_browser();
		$class = strtolower($b_info->browser);
		
		?>
		<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml" >
			
			<head>
				<title><?= $this->title ?></title>
				<?php $this->pageCss(); ?>
			</head>
			<body class="<?= $class ?>" >
		<?php 
	}
	
	protected function pageFooter()
	{
		?>
		
		<div style="border: 1px solid #ccc;" >
			Page Footer!
		</div>
		
		</body>
		</html>
		<?php 
	}
	
	protected function setTitle( $newTitle)
	{
		$this->title = $newTitle;
	}
	
	public function __destruct()
	{
		$this->pageFooter();
	}
	
	public function pageCss( $css = array())
	{
		$css[] = 'base';
		$dc = $this->data['dispatch_class'];
		$local_css = "$dc/$dc.css";		//so gear will be gear/gear.css
		
		if (file_exists( CFG_BASE . $local_css ))
		{
			$css[] = $dc . '/' . $dc . '.css';
		}
		
		foreach ($css as $file)
		{
			$link = CFG_WEB . 'css/' . $file . '.css';
			?> 	<link rel="stylesheet" type="text/css" href="<?= $link ?>" />	<?php 
		}
	}
	
}	//end of class